'use strict';
var React = require('react');
class ReImg extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            imgSrc:props.backImg
        }
    }

    //渲染完成后下载真正的图片
    componentDidMount(){
        var img=new Image();
        var visualDom=this;
        img.onload=function(){
            if(img.complete==true){
                visualDom.setState({
                    imgSrc:visualDom.props.realImg
                });
            }
        };

        //兼容IE
        img.onreadystatechange=function(){
            var state = img.readyState;
            if (state === 'loaded' || state === 'complete') {
                visualDom.setState({
                    imgSrc:visualDom.props.realImg
                });
            }
        };
        img.src=this.props.realImg;
    }

    render(){
        return <img className={this.props.reClass} src={this.state.imgSrc}/>
    }
}

module.exports = ReImg;